<?php
/**
 * Created by IntelliJ IDEA.
 * User: sunminqiang
 * Date: 17/3/3
 * Time: 下午3:48
 */
namespace app\admin\model;
use think\Model;
use think\Db;

class ContactModel extends Model
{
    protected $name = 'contact';

    // 开启自动写入时间戳字段

    /**
     * 根据搜索条件获取用户列表信息
     * @author [田建龙] [864491238@qq.com]
     * 联表查询sun
     */
    public function getContactByWhere($map, $Nowpage, $limits)
    {
        return $this->field('think_contact.*,id')->where($map)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [updateArticle 编辑文章]
     * @author [田建龙] [864491238@qq.com]
     */
    public function updateContact($param)
    {
        try {
            $result = $this->allowField(true)->save($param, ['id' => $param['id']]);
            if (false === $result) {
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            } else {
                return ['code' => 1, 'data' => '', 'msg' => '编辑成功'];
            }
        } catch (PDOException $e) {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    /**
     * [getOneArticle 根据文章id获取一条信息]
     * @author [田建龙] [864491238@qq.com]
     */
    public function getOneContact($id)
    {
        return $this->where('id', $id)->find();
    }



    public function getWarningByWhere($map, $Nowpage, $limits)
    {
        return Db::table('think_warning')->field('think_warning.*,id')->where($map)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [updateArticle 编辑文章]
     * @author [田建龙] [864491238@qq.com]
     */
    public function updateWarning($param)
    {
        try {
//            $result = Db::table('think_warning')->allowField(true)->save($param, ['id' => $param['id']]);
            $result = Db::name('warning')->where('id',$param['id'])->update($param);
            if (false === $result) {
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            } else {
                return ['code' => 1, 'data' => '', 'msg' => '编辑成功'];
            }
        } catch (PDOException $e) {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    /**
     * [getOneArticle 根据文章id获取一条信息]
     * @author [田建龙] [864491238@qq.com]
     */
    public function getOneWarning($id)
    {
        return Db::table('think_warning')->where('id', $id)->find();
    }






    public function getAboutByWhere($map, $Nowpage, $limits)
    {
        return Db::table('think_about')->where($map)->where('id','=',1)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [updateArticle 编辑文章]
     * @author [田建龙] [864491238@qq.com]
     */
    public function updateAbout($param)
    {
        try {
            //$result = Db::table('think_about')->save($param, ['id' => $param['id']]);
            $result = Db::name('about')->where('id',$param['id'])->update($param);
            if (false === $result) {
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            } else {
                return ['code' => 1, 'data' => '', 'msg' => '编辑成功'];
            }
        } catch (PDOException $e) {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    /**
     * [getOneArticle 根据文章id获取一条信息]
     * @author [田建龙] [864491238@qq.com]
     */
    public function getOneAbout($id)
    {
        return Db::table('think_about')->where('id', $id)->find();
    }



    public function getPicByWhere($map, $Nowpage, $limits)
    {
        return Db::table('think_about')->where($map)->where('id','=',2)->page($Nowpage, $limits)->order('id desc')->select();
    }

    /**
     * [updateArticle 编辑文章]
     * @author [田建龙] [864491238@qq.com]
     */
    public function updatePic($param)
    {
        try {
            //$result = Db::table('think_about')->save($param, ['id' => $param['id']]);
            $result = Db::name('about')->where('id',$param['id'])->update($param);
            if (false === $result) {
                return ['code' => 0, 'data' => '', 'msg' => $this->getError()];
            } else {
                return ['code' => 1, 'data' => '', 'msg' => '编辑成功'];
            }
        } catch (PDOException $e) {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }


    /**
     * [getOneArticle 根据文章id获取一条信息]
     * @author [田建龙] [864491238@qq.com]
     */
    public function getOnePic($id)
    {
        return Db::table('think_about')->where('id', $id)->find();
    }



}